import 'package:flutter/material.dart';
import 'package:homepad/iot/basic_types.dart';
import 'package:homepad/styles.dart';

class LightColorModeView extends StatelessWidget {
  final ValueChanged<ColorMode>? onChanged;
  final ColorMode mode;
  final bool enable;

  final height = 44.0;

  const LightColorModeView({super.key, required this.mode, required this.enable, this.onChanged});

  Text getItem(ColorMode item, TextStyle textStyle) {
    final activatedColor = switch (item) {
      ColorMode.hueAndSaturation => const Color(0xffDB2111),
      ColorMode.colorTemperature => const Color(0xFFE07300),
    };
    final color = item == mode ? activatedColor : Colors.white;
    return Text(item.name, style: textStyle.copyWith(color: color));
  }

  @override
  Widget build(BuildContext context) {
    final MyStyles styles = Theme.of(context).extension<MyStyles>()!;
    final items = ColorMode.values.toList();
    return Stack(children: [
      Positioned(
          right: items.last == mode ? 0 : null,
          child: Container(
            height: height,
            width: 70,
            decoration: BoxDecoration(borderRadius: styles.radius, color: Colors.white),
          )),
      Container(
        height: height,
        padding: const EdgeInsets.symmetric(horizontal: 5),
        decoration: BoxDecoration(
            borderRadius: styles.radius, border: styles.border, color: Colors.transparent),
        child: Row(
          children: items.map<Widget>((item) {
            return GestureDetector(
                onTap: () {
                  if (enable) onChanged?.call(item);
                },
                child: SizedBox(
                    width: 60,
                    child: Center(
                      child: getItem(item, styles.textStyle),
                    )));
          }).toList(),
        ),
      )
    ]);
  }
}
